{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.colors as colors\n",
    "import matplotlib.cbook as cbook\n",
    "import sys\n",
    "dirwork ='TCHEM_INSTALL_PATH/example/runs/scripts/'\n",
    "sys.path.append(dirwork)\n",
    "import pmixSample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000 900\n"
     ]
    }
   ],
   "source": [
    "# Pressure, Temperature, phi(stoichiometric ratio)\n",
    "one_atm = 101325\n",
    "TempMax = 1000 \n",
    "TempMin = 900 \n",
    "\n",
    "PressureMax = 1*one_atm; # atm\n",
    "PressureMin = 1*one_atm; # atm\n",
    "\n",
    "phiMax = 0.5; # \n",
    "phiMin = 3; # \n",
    "print(TempMax,TempMin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p 100\n"
     ]
    }
   ],
   "source": [
    "Npp = 1\n",
    "Npt = 10\n",
    "Npphi = 10\n",
    "N = Npp*Npt*Npphi\n",
    "pressure    = [PressureMin]#[PressureMin, PressureMax] # , np.linspace(PressureMin, PressureMax, Npp) #\n",
    "temperature = np.linspace(TempMin, TempMax, Npt)\n",
    "eqratio     = np.linspace(phiMin, phiMax, Npphi)\n",
    "p, temp, phi = np.meshgrid(pressure, temperature,eqratio)\n",
    "print('p',np.size(p))\n",
    "p    = p.reshape(np.size(p)) #flatten()\n",
    "temp = temp.reshape(np.size(temp))#flatten()\n",
    "phi  = phi.reshape(np.size(phi))#flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "Nvar = 4\n",
    "sample = np.zeros([N,Nvar])\n",
    "fuel =\"H2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(N):\n",
    "    sample[i,0] = temp[i]\n",
    "    sample[i,1] = p[i]\n",
    "    Yp_fuel, Yr_o2 = pmixSample.getMassFractionH2(phi[i])\n",
    "    sample[i,2] = Yp_fuel\n",
    "    sample[i,3] = Yr_o2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "savedir = 'inputs/'\n",
    "header_fuel = \"T P \"+fuel+\" O2\"\n",
    "np.savetxt(savedir+'/sample.dat',sample,header=header_fuel,comments='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "ReactionNumber = [0, 2, 4] # change parameters for reaction 0 and 2 \n",
    "Nparameter = len(ReactionNumber); "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The forward rate constant has typically an Arrhenius expression:\n",
    "\n",
    "$${k_f}_i=A_iT^{\\beta_i}\\exp\\left(-\\frac{E_i}{RT}\\right)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "μ=0\n",
    "σ=0.25\n",
    "A_modifier = np.random.lognormal(μ, σ, size=(N, Nparameter))\n",
    "β_modifier = np.ones((N, Nparameter))\n",
    "E_modifier = np.random.lognormal(μ, σ, size=(N, Nparameter))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "sampleParam = np.vstack((A_modifier[0,:],β_modifier[0,:],E_modifier[0,:]))\n",
    "for sp in range(1,N):\n",
    "    sampleParam = np.vstack((sampleParam, A_modifier[sp,:], β_modifier[sp,:], E_modifier[sp,:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "header =\"\"\n",
    "for Reac in ReactionNumber:\n",
    "    header += str(Reac) + \" \"\n",
    "np.savetxt(savedir+'/ParameterModifiers.dat',sampleParam,header=header,comments='')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
